﻿EntityProjectile = Eg.Entity.extend({
  name: 'projectile',
  size: {
    x: 6,
    y: 3
  },
  offset: {
    x: 1,
    y: 2
  },
  maxVel: {
    x: 200,
    y: 0
  },
  gravityFactor: 0,
  type: Eg.Entity.TYPE.NONE,
  checkAgainst: Eg.Entity.TYPE.B,
  collides: Eg.Entity.COLLIDES.NEVER,
  flip: false,
  hasHit: false,
  animSheet: new Eg.AnimationSheet('Resource/projectile.png', 8, 8),
  init: function (x, y, settings) {
    this.parent(x, y, settings);
    this.vel.x = (settings.flip ? -this.maxVel.x : this.maxVel.x);
    this.addAnim('idle', 1, [0]);
    this.addAnim('hit', 0.1, [0, 1, 2, 3, 4, 5], true);
  },
  update: function () {
    if (this.hasHit && this.currentAnim.loopCount > 0) {
      this.kill();
    }
    this.parent();
    this.currentAnim.flip.x = this.flip;
  },
  handleMovementTrace: function (res) {
    this.parent(res);
    if (res.collision.x || res.collision.y) {
      this.currentAnim = this.anims.hit;
      this.hasHit = true;
    }
  },
  check: function (other) {
    if (!this.hasHit) {
      other.receiveDamage(10, this);
      this.hasHit = true;
      this.currentAnim = this.anims.hit;
      this.vel.x = 0;
    }
  }
});